package me.baicai.weixin.provider.repository;

import me.baicai.weixin.application.Result;
import me.baicai.weixin.entity.gcb.Withdrawal;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface WithdrawalRepository extends JpaRepository<Withdrawal, Long>
{

    // 按照状态查询申请列表
    Page<Withdrawal> findAllByStatus(String status, Pageable pageable);

    // 按照状态查询自己的申请列表
    Page<Withdrawal> findAllByOpenidAndStatus(String openid, String status, Pageable pageable);

    Withdrawal getWithdrawalById(Integer id);

    List<Withdrawal> findAllByOpenid(String openid, Pageable pageable);

    @Query(value = "select * from withdrawal w where w.status = ?1 and w.uid like ?2 or w.status = ?1 and w.name like ?2", nativeQuery = true)
    Page<Withdrawal> findAllByStatus(String status, String s, Pageable pageable);

    @Query(value = "select * from withdrawal w where w.uid like ?2 or w.name like ?2", nativeQuery = true)
    Page<Withdrawal> findAll(String s, Pageable pageable);

    @Query(value = "select * from withdrawal w where w.status = ?1 and w.uid like ?2 or w.status = ?1 and w.name like ?2", nativeQuery = true)
    Page<Withdrawal> findAll(String s, String t, Pageable pageable);

    @Query(value = "select `value` from dict_detail where label = '提现费率'", nativeQuery = true)
    Float getRate();
}
